package com.store.Controller;

import com.common.entity.Result;
import com.github.pagehelper.PageInfo;
import com.store.Pojo.Storehouse;
import com.store.Service.StorehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/storehouse")
public class StorehouseController {
    @Autowired
    private StorehouseService storehouseService;
    //添加修改
    @PostMapping("/AddOrUpdate")
    public Result AddOrUpdate(@RequestBody Storehouse storehouse){
        if(storehouse.getStorehouseId()==null){
            storehouseService.AddStore(storehouse);
        }else {
            storehouseService.UpdateStore(storehouse);
        }
        return Result.success();
    }
    //查询
    @GetMapping("/SearchStore")
    public Result SearchStore(@RequestParam Integer pageNum,
                              @RequestParam Integer pageSize,
                              @RequestParam String storehouseName){
        PageInfo<Storehouse> storehousePageInfo=storehouseService.SearchStore(pageNum,pageSize,storehouseName);
        return  Result.success(storehousePageInfo);
    }
    //删除
    @DeleteMapping("/DelStore")
    public Result DelStore(@RequestParam Integer Id){
        storehouseService.DelStore(Id);
        return  Result.success();
    }
    //查询列表
    @GetMapping("list")
    public Result searchlist(){
        List<Storehouse> searchlist=storehouseService.searchlist();
        return  Result.success(searchlist);
    }
}
